package com.travelpass.slidingMenu;

import java.util.ArrayList;

import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;

import com.slidingmenu.lib.SlidingMenu;
import com.travelpass.R;
import com.travelpass.fragments.Horaires;

public class MainActivity extends BaseActivity{
	
	private static Fragment mContent;
	
	public static MenuList ml;
	
	public static MainActivity mainActivity;
	
	public MainActivity(){
		super(R.string.app_name);
		
	}
	
	public static MainActivity getIns(){
		if(mainActivity == null){
			mainActivity=new MainActivity();
		}
		return mainActivity;
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		
		mContent = new Horaires();
		mainActivity=this;
		setContentView(R.layout.content_frame);
		getSupportFragmentManager()
		.beginTransaction()
		.replace(R.id.content_frame, mContent).commit();
		
		
		ml = new MenuList(getSlidingMenu(), getSupportActionBar(), getSupportFragmentManager());
		setBehindContentView(R.layout.menu_frame);
		getSupportFragmentManager()
		.beginTransaction()
		.replace(R.id.menu_frame, ml).commit();
		
		getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
		setSlidingActionBarEnabled(true);
		
	}
	
	
	@Override
	public void onSaveInstanceState(Bundle outState){
		super.onSaveInstanceState(outState);
		try{
			getSupportFragmentManager().putFragment(outState, "mContent", mContent);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void switchContent(Fragment fragment){
		mContent = fragment;
		getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, fragment).commit();
		getSlidingMenu().showContent();
	}
	
	@Override
	public void onConfigurationChanged(Configuration newConfig) {
	  super.onConfigurationChanged(newConfig);
	}
	
	public static ArrayList<String> villes;

}
